package dao;


import java.util.List;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.log4j.Logger;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import dao.Admin;

public class AdminDao extends HibernateDaoSupport{
	public List findByProperty(String propertyName, Object value) {
		try {
			String queryString = "from Admin as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {throw re;}
	} 
	public boolean doLogin(String username,String password){
		Logger log = Logger.getLogger(AdminDao.class.getName());
		
		if(this.findByProperty("username",username).size()!=0){
			Admin a=(Admin) this.findByProperty("username",username).get(0);
			
				log.info(DigestUtils.md5Hex(password));
				log.info(a.getPassword());
			if(a.getPassword().equals(DigestUtils.md5Hex(password))==true){
				
				return true;
			}
			else{
				
				return false;
			}
		}else return false;
     }
}
